package com.itheima.day09_set;

import java.util.TreeSet;
//方法2 用Comparator接口来实现
public class Test03_2 {
    public static void main(String[] args) {
        TreeSet<Student> t = new TreeSet<>((o1, o2) -> {
            int result = o2.getScore() - o1.getScore();
            result = result == 0 ? 1 : result;
            if (o1.getScore() - o2.getScore() == 0 && o1.getAge() - o2.getAge() == 0) {
                result = o1.getName().compareTo(o2.getName());
            }
            return result;
        });
        t.add(new Student("Tom",20,90));
        t.add(new Student("Jerry",22,95));
        t.add(new Student("John",20,100));
        t.add(new Student("Lily",22,100));
        t.add(new Student("Lucy",22,90));
        t.add(new Student("Kevin",22,90));

        for (Student student : t) {
            System.out.println(student);
        }

    }

}
class Student {
    private String name;
    private int age;
    private int score;

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

    public Student() {
    }

    public Student(String name, int age, int score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    }